---
title: gluestack-ui Button Component | Installation, Usage, and API

description: Trigger an action or event with customizable size, shape, color, and behavior.

pageTitle: Button

pageDescription: Trigger an action or event with customizable size, shape, color, and behavior.

showHeader: true
---

import { Meta } from '@storybook/addon-docs';

<Meta title="with-nativewind/Components/Forms/Button" />

import {
  Button,
  ButtonText,
  ButtonSpinner,
  ButtonIcon,
  Icon,
  ArrowUpIcon,
  InfoIcon,
  AddIcon,
  Box,
  VStack,
  Heading,
  Text,
  Input,
  InputField,
  Center,
  ArrowLeftIcon,
  EditIcon
} from '../../core-components/nativewind';
import { transformedCode } from '../../utils';
import {
  AppProvider,
  CodePreview,
  Table,
  TableContainer,
  InlineCode,
  Tabs
} from '@gluestack/design-system';
import Wrapper from '../../core-components/nativewind/Wrapper';
import { CollapsibleCode } from '@gluestack/design-system';
import colors from 'tailwindcss/colors';
import AnatomyImage from '../../extra-components/nativewind/AnatomyImage';

This is an illustration of **Button** component.

<Wrapper>
  <CodePreview
    showComponentRenderer={true}
    showArgsController={true}
    metaData={{
      code: `
        <Button {...props}>
          <ButtonText>Hello World!</ButtonText>
        </Button>
      `,
      transformCode: (code) => {
        return transformedCode(code);
      },
      scope: { Button, ButtonText, ButtonIcon, Wrapper },
      argsType: {
        size: {
          control: 'select',
          options: ['xs', 'sm', 'md', 'lg'],
          default: 'md',
        },
        variant: {
          control: 'select',
          options: ['solid', 'outline', 'link'],
          default: 'solid',
        },
        action: {
          control: 'select',
          options: ['primary', 'secondary', 'positive', 'negative'],
          default: 'primary',
        },
      },
    }}
  />
</Wrapper>

<br />

## Installation

<Tabs value="cli" type="section">
  <Tabs.TabList>
      <Tabs.Tab value="cli">
        <Tabs.TabTitle>CLI</Tabs.TabTitle>
      </Tabs.Tab>
     <Tabs.Tab value="manual">
        <Tabs.TabTitle>Manual</Tabs.TabTitle>
     </Tabs.Tab>
  </Tabs.TabList>
  <Tabs.TabPanels>
    <Tabs.TabPanel value="cli">
<>

### Run the following command:
  ```bash
  npx gluestack-ui add button
  ```
</>
    </Tabs.TabPanel>
    <Tabs.TabPanel value="manual"> 
<>

### Step 1: Install the following dependencies:
```bash
npm i @gluestack-ui/button
```

### Step 2: Copy and paste the following code into your project.
<CollapsibleCode>

```jsx 
%%-- File: core-components/nativewind/button/index.tsx --%% 
```
</CollapsibleCode>

### Step 3: Update the import paths to match your project setup.
</>
    </Tabs.TabPanel>
  </Tabs.TabPanels>
</Tabs>

## API Reference

To use this component in your project, include the following import statement in your file.

```jsx
import {
  Button,
  ButtonText,
  ButtonSpinner,
  ButtonIcon,
  ButtonGroup,
} from '@/components/ui/button';
```

<AnatomyImage mobileUrl='https://i.imgur.com/64ja4mQ.png' webUrl='https://i.imgur.com/eLSw4hK.png' classNameStyle='aspect-[513/296] md:aspect-[736/228]' />

```jsx
export default () => (
  <ButtonGroup>
    <Button>
      <ButtonText />
      <ButtonSpinner />
      <ButtonIcon />
    </Button>
  </ButtonGroup>
);
```

### Component Props

This section provides a comprehensive reference list for the component props, detailing descriptions, properties, types, and default behavior for easy project integration.

#### Button

Contains all button related layout style props and actions. It inherits all the properties of React Native's [Pressable](https://reactnative.dev/docs/pressable) component.

<>
  <TableContainer>
    <Table>
      <Table.THead>
        <Table.TR>
          <Table.TH>
            <Table.TText>Prop</Table.TText>
          </Table.TH>
          <Table.TH>
            <Table.TText>Type</Table.TText>
          </Table.TH>
          <Table.TH>
            <Table.TText>Default</Table.TText>
          </Table.TH>
          <Table.TH>
            <Table.TText>Description</Table.TText>
          </Table.TH>
        </Table.TR>
      </Table.THead>
      <Table.TBody>
        <Table.TR>
          <Table.TD>
            <Table.TText>
              <InlineCode>isHovered</InlineCode>
            </Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>bool</Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>false</Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>{`To manually set hover to the button.`}</Table.TText>
          </Table.TD>
        </Table.TR>
        <Table.TR>
          <Table.TD>
            <Table.TText>
              <InlineCode>isPressed</InlineCode>
            </Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>bool</Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>false</Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>{`To manually set pressable state to the button.`}</Table.TText>
          </Table.TD>
        </Table.TR>
        <Table.TR>
          <Table.TD>
            <Table.TText>
              <InlineCode>isFocused</InlineCode>
            </Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>bool</Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>false</Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>{`To manually set focused state to the button.`}</Table.TText>
          </Table.TD>
        </Table.TR>
        <Table.TR>
          <Table.TD>
            <Table.TText>
              <InlineCode>isDisabled</InlineCode>
            </Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>bool</Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>false</Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>{`To manually set disable to the button.`}</Table.TText>
          </Table.TD>
        </Table.TR>
      </Table.TBody>
    </Table>
  </TableContainer>
</>

#### ButtonText

Contains all text related layout style props and actions. It inherits all the properties of React Native's [Text](https://reactnative.dev/docs/text) component.

#### ButtonGroup

Contains all group related layout style props and actions. It inherits all the properties of React Native's [View](https://reactnative.dev/docs/view) component.

<>
  <TableContainer>
    <Table>
      <Table.THead>
        <Table.TR>
          <Table.TH>
            <Table.TText>Prop</Table.TText>
          </Table.TH>
          <Table.TH>
            <Table.TText>Type</Table.TText>
          </Table.TH>
          <Table.TH>
            <Table.TText>Default</Table.TText>
          </Table.TH>
          <Table.TH>
            <Table.TText>Description</Table.TText>
          </Table.TH>
        </Table.TR>
      </Table.THead>
      <Table.TBody>
        <Table.TR>
          <Table.TD>
            <Table.TText>
              <InlineCode>flexDirection</InlineCode>
            </Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>
              'row' | 'column' | 'row-reverse' | 'column-reverse'
            </Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>'row'</Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>
              Set the direction of Button group to vertical or horizontal
            </Table.TText>
          </Table.TD>
        </Table.TR>
        <Table.TR>
          <Table.TD>
            <Table.TText>
              <InlineCode>isDisabled</InlineCode>
            </Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>bool</Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>false</Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>{`When true, this will disable all the buttons in a ButtonGroup.`}</Table.TText>
          </Table.TD>
        </Table.TR>
        <Table.TR>
          <Table.TD>
            <Table.TText>
              <InlineCode>isAttached</InlineCode>
            </Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>bool</Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>false</Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>{`When attached, all buttons will be attached to each other.`}</Table.TText>
          </Table.TD>
        </Table.TR>
        <Table.TR>
          <Table.TD>
            <Table.TText>
              <InlineCode>reversed</InlineCode>
            </Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>bool</Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>false</Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>{`To reverse the order of components.`}</Table.TText>
          </Table.TD>
        </Table.TR>
        <Table.TR>
          <Table.TD>
            <Table.TText>
              <InlineCode>space</InlineCode>
            </Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>string</Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>md</Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>
              It sets the space between different buttons.
            </Table.TText>
          </Table.TD>
        </Table.TR>
      </Table.TBody>
    </Table>
  </TableContainer>
</>

#### ButtonSpinner

Contains all spinner related layout style props and actions.
It inherits all the properties of React Native's [ActivityIndicator](https://reactnative.dev/docs/activityindicator) component.

#### ButtonIcon

Contains all Icon related layout style props and actions. It inherits all the properties of React Native's [View](https://reactnative.dev/docs/view) component.

### Features

- Keyboard support for actions.
- Support for hover, focus and active states.
- Option to add your styles or use the default styles.

### Accessibility

We have outlined the various features that ensure the Button component is accessible to all users, including those with disabilities. These features help ensure that your application is inclusive and meets accessibility standards.Adheres to the [WAI-ARIA design pattern](https://www.w3.org/WAI/ARIA/apg/patterns/button/).

#### Keyboard

- `Tab`: Moves focus to the next focusable element.
- `Shift + Tab`: Moves focus to the previous focusable element.
- `Enter`: Triggers the button's action.

### Screen Reader

- VoiceOver: When the button is focused, the screen reader will announce the button's label and its current state.

### Focus Management

- The `onFocus` and `onBlur` props to manage focus states and provide visual cues to users. This is especially important for users who rely on keyboard navigation.

### Props

Button component is created using Pressable component from react-native. It extends all the props supported by [React Native Pressable](https://reactnative.dev/docs/pressable#props), [utility props](/ui/docs/styling/utility-and-sx-props) and the props mentioned below.

#### Button

<>
  <TableContainer>
    <Table>
      <Table.THead>
        <Table.TR>
          <Table.TH>
            <Table.TText>Name</Table.TText>
          </Table.TH>
          <Table.TH>
            <Table.TText>Value</Table.TText>
          </Table.TH>
          <Table.TH>
            <Table.TText>Default</Table.TText>
          </Table.TH>
        </Table.TR>
      </Table.THead>
      <Table.TBody>
        <Table.TR>
          <Table.TD>
            <Table.TText>
              <InlineCode>action</InlineCode>
            </Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>
              {'primary | secondary | positive | negative | default'}
            </Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>primary</Table.TText>
          </Table.TD>
        </Table.TR>
        <Table.TR>
          <Table.TD>
            <Table.TText>
              <InlineCode>variant</InlineCode>
            </Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>link | outline | solid</Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>solid</Table.TText>
          </Table.TD>
        </Table.TR>
        <Table.TR>
          <Table.TD>
            <Table.TText>
              <InlineCode>size</InlineCode>
            </Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>xs | sm | md | lg | xl</Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>md</Table.TText>
          </Table.TD>
        </Table.TR>
      </Table.TBody>
    </Table>
  </TableContainer>
</>

> Note: These props are exclusively applicable when utilizing the default configuration of gluestack-ui/config. If you are using a custom theme, these props may not be available.

### Examples

The Examples section provides visual representations of the different variants of the component, allowing you to quickly and easily determine which one best fits your needs. Simply copy the code and integrate it into your project.

#### Button with Loading State

A loading button is a type of button component that provides visual feedback to the user during an action that takes some time to complete. It typically displays an animated loading icon or spinner indicating the action is in progress.

<Wrapper>
  <CodePreview
    showComponentRenderer={true}
    showArgsController={false}
    metaData={{
      code: `
        <Button className='p-3'>
        {/* colors is imported from tailwindcss/colors */}
          <ButtonSpinner color={colors.gray[400]} />
          <ButtonText className='font-medium text-sm ml-2'>Please wait...</ButtonText>
        </Button>
      `,
      transformCode: (code) => {
        return transformedCode(code);
      },
      scope: { Button, ButtonText, Wrapper, ButtonSpinner, colors },
      argsType: {},
    }}
  />
</Wrapper>

#### Icon Button

A button with an icon integrates a visual symbol within the button component, enhancing its appearance and providing a recognizable and intuitive representation of its associated action or functionality.

<Wrapper>
  <CodePreview
    showComponentRenderer={true}
    showArgsController={false}
    metaData={{
      code: `
        <Button
      size="lg"
      className="rounded-full p-3.5"
    >
    {\/* EditIcon is imported from 'lucide-react-native' *\/}
      <ButtonIcon as={EditIcon} />
    </Button>
      `,
      transformCode: (code) => {
        return transformedCode(code);
      },
      scope: { Button, ButtonIcon, Wrapper, EditIcon },
      argsType: {},
    }}
  />
</Wrapper>

#### Link Button

A button with a link combines the interactive behavior of a button component with the ability to navigate to a specified URL, providing a clickable element for users to access external resources or internal pages.

<Wrapper>
  <CodePreview
    showComponentRenderer={true}
    showArgsController={false}
    metaData={{
      code: `
        <Button variant='link'>
          <ButtonText className='font-medium text-sm text-typography-900' >
            Back to top
          </ButtonText>
          <ButtonIcon as={ArrowUpIcon}
           className='h-3 w-3 text-background-900 ml-1' />
        </Button>
      `,
      transformCode: (code) => {
        return transformedCode(code);
      },
      scope: { Button, ButtonText, ButtonIcon, Wrapper, ArrowUpIcon },
      argsType: {},
    }}
  />
</Wrapper>

#### Button With Icon

The icon component incorporates a button component, combining visual representation with interactive functionality for seamless user interaction.

<Wrapper>
  <CodePreview
    showComponentRenderer={true}
    showArgsController={false}
    metaData={{
      code: `
        <Box>
          <Button>
          <ButtonIcon as={InfoIcon} className='mr-2'/>
            <ButtonText>Left Icon</ButtonText>
          </Button>
          <Button variant="solid" className='mt-2'>
          <ButtonText>Right Icon</ButtonText>
            <ButtonIcon as={AddIcon} className='ml-2'/>
          </Button>
        </Box>
      `,
      transformCode: (code) => {
        return transformedCode(code);
      },
      scope: { Button, ButtonText, ButtonIcon, Wrapper, Icon, InfoIcon, AddIcon, Box },
      argsType: {},
    }}
  />
</Wrapper>

#### Button with Full Width

The button with full width component utilizes a button component, expanding its width to occupy the entire available space, creating a visually prominent and easily accessible interface element.

<Wrapper>
  <CodePreview
    _rendererWrapper={{ py: '$8' }}
    showComponentRenderer={true}
    showArgsController={false}
    metaData={{
      code: `
        <Center>
          <Box className='p-5 max-w-96 border border-background-300 rounded-lg'>
            <VStack className='pb-4' space='xs'>
              <Heading className='leading-[30px]'>
                Set new password
              </Heading>
              <Text className='text-sm'>
                Almost done. Enter your new password and you are all set.
              </Text>
            </VStack>
            <VStack space='xl' className='py-2'>
              <Input>
                <InputField
                  className='py-2'
                  placeholder="New password"
                />
              </Input>
              <Input>
                <InputField
                  className='py-2'
                  placeholder="Confirm new password"
                />
              </Input>
            </VStack>
            <VStack space='lg' className='pt-4'>
              <Button
                size='sm'
              >
                <ButtonText>
                  Submit
                </ButtonText>
              </Button>
              <Box className='flex flex-row'>
                <Button variant='link' size='sm' className='p-0'>
                  {\/* ArrowLeftIcon is imported from 'lucide-react-native' *\/}
                  <ButtonIcon
                    className='mr-1'
                    size='md'
                    as={ArrowLeftIcon}
                  />
                  <ButtonText
                  >
                    Back to login
                  </ButtonText>
                </Button>
              </Box>
            </VStack>
          </Box>
        </Center>
      `,
      transformCode: (code) => {
        return transformedCode(code);
      },
      scope: {
        Button,
        ButtonText,
        ButtonIcon,
        Wrapper,
        VStack,
        Box,
        Heading,
        Text,
        Input,
        InputField,
        Icon,
        Center,
        ArrowLeftIcon,
      },
      argsType: {},
    }}
  />
</Wrapper>
